package com.cn.kehong.controller;



import com.cn.kehong.api.IFileInfoService;
import com.cn.kehong.domain.FileInfo;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@RequestMapping("/file")
public class FileInfoController {

    @Autowired
    private IFileInfoService fileInfoService;

    @RequestMapping("/queryBoardFileList")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryBoardFileList(QueryForm queryForm) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/queryFileList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryFileList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/queryFileListByTypes/{frontToken}")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryFileListByTypes(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileListByTypes(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/queryFileListByTypes")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryFileListByTypes(@RequestBody QueryForm queryForm) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileListByTypes(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/queryFileList")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryFileList(QueryForm queryForm) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/updateFile/{frontToken}")
    public JsonResponse<String> updateFile(@RequestBody FileInfo fileInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.updateFile(fileInfo);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/updateBatchFile/{frontToken}")
    public JsonResponse<String> updateFile(@RequestBody List<FileInfo> fileInfos, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.updateBatchFile(fileInfos);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/updateFileCheckStatus/{frontToken}")
    public JsonResponse<String> updateFileCheckStatus(@RequestBody List<FileInfo> fileInfos, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.updateFileCheckStatus(fileInfos);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/addFile/{frontToken}")
    public JsonResponse<String> addFile(@RequestBody FileInfo fileInfo, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.addFile(fileInfo);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/deleteFileByIds/{frontToken}")
    public JsonResponse<String> deleteFileByIds(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.deleteFileByIds(queryForm);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/deleteFileByRelateId/{frontToken}")
    public JsonResponse<String> deleteFileByRelateId(String relateId,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.deleteFileByRelateId(relateId);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    @ResponseBody
    @RequestMapping("/selectFileByRelateId/{frontToken}")
    public JsonResponse<List<FileInfo>> selectFileByRelateId(@RequestBody QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<>();
        List<FileInfo> result = fileInfoService.selectFileByRelateId(queryForm);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }


    @RequestMapping("/api/queryFileList")
    @ResponseBody
    public JsonResponse<List<FileInfo>> queryApiFileList(QueryForm queryForm) throws Exception {
        JsonResponse<List<FileInfo>> response = new JsonResponse<List<FileInfo>>();
        List<FileInfo> list  = fileInfoService.queryFileList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/addFileByApp")
    public JsonResponse<String> addFileByApp(@RequestParam("file") MultipartFile file) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = fileInfoService.addFileByApp(file);
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

}
